package org.example;

import java.util.List;
import java.util.function.Consumer;

/**
 * @Author xhw
 * @Date 2023/11/9
 * @Version 1.0
 */
public class TreeMain {

    public static void main(String[] args) {
        Tree tree = new Tree();
        TreeNode root = new TreeNode(1);
        TreeNode node2 = new TreeNode(2);
        TreeNode node3 = new TreeNode(3);
        TreeNode node4 = new TreeNode(4);
        TreeNode node5 = new TreeNode(5);
        TreeNode node6 = new TreeNode(6);
        TreeNode node7 = new TreeNode(7);

        root.getChildren().add(node2);
        root.getChildren().add(node3);
        node2.getChildren().add(node4);
        node2.getChildren().add(node5);
        node3.getChildren().add(node6);
        node3.getChildren().add(node7);
        tree.root = root;
        System.out.println("深度迭代");
        tree.depthFirstSearch(root);
        System.out.println();
        System.out.println("广度迭代");
        tree.breadthFirstSearch();
        Consumer<TreeNode> printMode = (node -> System.out.print(node.getVal()));
        System.out.println();
        System.out.println("深度迭代");
        // 调用 deep 方法进行深度迭代操作
        tree.deep(tree.root, printMode);
        System.out.println();
        System.out.println("广度迭代");
        tree.breadth(root, printMode);
    }
}
